package com.example.exchange.service.exchange.impl;

import com.example.exchange.client.exchange.ExchangeClient;
import com.example.exchange.service.exchange.IExchangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import reactor.core.publisher.Mono;

@Service
public class ExchangeServiceImpl implements IExchangeService {
  @Autowired
  private ExchangeClient exchangeClient;

  @Override
  public Mono<Object> realtime(String location) {
    if (!StringUtils.hasText(location)) {
      return Mono.empty();
    }

    return Mono.just(exchangeClient.realtime(location));

  }

  @Override
  public Mono<Object> minutely(String location) {
    if (!StringUtils.hasText(location)) {
      return Mono.empty();
    }
    return Mono.just(exchangeClient.minutely(location));

  }

  @Override
  public Mono<Object> weather(String location, Integer dailysteps, Integer hourlysteps) {
    if (!StringUtils.hasText(location)) {
      return Mono.empty();
    }
    dailysteps = Math.max(2, dailysteps);
    dailysteps = Math.min(15, dailysteps);

    hourlysteps = Math.max(1, hourlysteps);
    hourlysteps = Math.min(360, hourlysteps);

    return Mono.just(exchangeClient.weather(location, dailysteps, hourlysteps));

  }
}
